<template>
  <a-card title="平台参数">
    <a-row>
      <a-col span="4">

      </a-col>
      <a-col span="14">
        <a-spin :spinning="confirmSpin">
          <span style="font-size: 16px;font-weight: bold;margin-right: 20px;"> 平台名称: </span>
          <a-input placeholder="请输入平台名称" style="width: 400px;"
                   v-model="configData.name"/>
          <p style="margin-left: 100px;margin-top: 20px;margin-bottom: 20px;"></p>
          <br/>

          <span style="font-size: 16px;font-weight: bold;margin-right: 20px;"> 联系方式: </span>
          <a-input placeholder="请输入联系方式" style="width: 400px;"
                   v-model="configData.tel"/>
          <p style="margin-left: 100px;margin-top: 20px;margin-bottom: 20px;"></p>
          <br/>

          <span style="font-size: 16px;font-weight: bold;margin-right: 20px;"> 智齿客服key: </span>
          <a-input placeholder="请输入智齿客服key" style="width: 400px;"
                   v-model="configData.sobotKey"/>
          <p style="margin-left: 100px;margin-top: 20px;margin-bottom: 20px;"></p>
          <br/>
          <a-button type="primary" style="margin-left: 100px;" size="large"
                    @click="updateConfigData">确认修改
          </a-button>
        </a-spin>
      </a-col>
      <a-col span="6">

      </a-col>
    </a-row>
  </a-card>
</template>
<script>
import {getAction, putAction} from "@/api/manage";
import {BoneCommonMixin} from "@/mixins/BoneCommonMixin";

export default {
  name: "PlatformParams",
  mixins: [BoneCommonMixin],
  components: {},
  data() {
    return {
      description: "平台参数配置",
      url: {
        queryByType: "/cms/config/queryByType",
        updateByType: "/cms/config/updateByType",
      },
      confirmSpin: false,
      type: "platformConfig",
      configData: {
        name: "",
        tel: "",
        sobotKey: "",
      },
    }
  },
  created() {
    this.queryConfigData();
  },
  methods: {
    queryConfigData() {
      this.confirmSpin = true;
      getAction(this.url.queryByType, {type: this.type}).then(res => {
        if (res.code === 200) {
          this.configData = JSON.parse(res.result);
          this.confirmSpin = false;
          console.log(this.configData);
        } else {
          this.showError(res.message);
        }
      })
    },
    updateConfigData() {
      let name = this.configData.name;
      let tel = this.configData.tel;
      let sobotKey = this.configData.sobotKey;
      if (name == null || name === '') {
        this.showWarn("请填写平台名称");
        return;
      }
      if (tel == null || tel === '') {
        this.showWarn("请填写联系方式");
        return;
      }
      if (sobotKey == null || sobotKey === '') {
        this.showWarn("请填写智齿客服key");
        return;
      }
      let params = JSON.stringify(this.configData);
      this.confirmSpin = true;
      putAction(this.url.updateByType, {type: this.type, params: params}).then(res => {
        if (res.code === 200) {
          this.showSuccess(res.message);
          this.confirmSpin = false;
        } else {
          this.showError(res.message);
        }
      })
    }
  }
}
</script>

<style scoped>

</style>